package src.greedy_algorithms;

import java.util.*;

/**
 * @author starsea
 * @date 2024-08-27 8:26
 */

public class Test04 {
    public static void main(String[] args) {
        String s = "abccccdd";
        int c = longestPalindrome(s);

    }

    public static int longestPalindrome(String s) {
        Map<Character, Integer> map = new HashMap<>();
        for (char ch : s.toCharArray()) {
            if (map.containsKey(ch)) {
                map.put(ch, map.get(ch) + 1);
            } else {
                map.put(ch, 1);
            }
        }
        int ret = 0;
        for (int count : map.values()) {
            ret += (count / 2) * 2;
        }
        if (s.length() != ret) {
            ret += 1;
        }
        return ret;
    }
}
